import { callInferenceService } from './src/services/aiInferenceService.js';
import path from 'path';
import fs from 'fs';

async function testAIIntegration() {
  try {
    console.log('🧪 测试后端AI推理集成...');

    // 查找测试图像
    const uploadDir = './uploads/medical_images';
    const files = fs.readdirSync(uploadDir);
    const testFile = files.find(f => f.endsWith('.jpg') || f.endsWith('.jpeg') || f.endsWith('.png'));

    if (!testFile) {
      console.log('❌ 没有找到测试图像');
      return;
    }

    const filePath = path.join(uploadDir, testFile);
    const testTaskId = Date.now(); // 使用时间戳作为测试任务ID

    console.log('📝 测试任务ID:', testTaskId);
    console.log('📁 测试文件:', filePath);

    await callInferenceService(testTaskId, filePath);

    console.log('✅ 后端AI推理集成测试成功!');

  } catch (error) {
    console.error('❌ 后端AI推理集成测试失败:', error.message);
    console.error('详细错误:', error);
  }
}

// 运行测试
testAIIntegration();